package com.focusai.efairy.utils;

import android.os.Build;

import com.focusai.efairy.utils.log.Log;

import java.lang.reflect.Field;

/**
 * 设备工具类
 *
 * @author lifeng
 *
 */
public class DeviceUtils {

	public static String getManufacturer(){

        // 使用反射来收集设备信息.在Build类中包含各种设备信息,
        // 例如: 系统版本号,设备生产商 等帮助调试程序的有用信息
        Field[] fields = Build.class.getDeclaredFields();
        String manufacturer = "";
        for (Field field : fields) {
            try {
//				field.setAccessible(true);
//                 Log.D("DeviceUtils---->>", field.getName() + " : " + field.get(null));
                if("MANUFACTURER".equals(field.getName())){
                    manufacturer = field.get(null)+"";
                    if("HUAWEI".equalsIgnoreCase(manufacturer) || manufacturer.contains("HUAWEI") || manufacturer.contains("huawei")
                            || manufacturer.contains("Huawei") || manufacturer.contains("HuaWei")){

                        return "HUAWEI";
                    }else if("XIAOMI".equalsIgnoreCase(manufacturer) || manufacturer.contains("XIAOMI") || manufacturer.contains("xiaomi")
                            || manufacturer.contains("Xiaomi") ||manufacturer.contains("XiaoMi")){

                        return "Xiaomi";
                    }else{
                        return manufacturer;
                    }
                }
            } catch (Exception e) {
                Log.E("DeviceUtils", "Error while collect DeviceUtils info"+e);
            }
        }
        return manufacturer;
    }
}
